import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';
import 'package:yw_bapp/utils/timeHandle.dart';
import 'package:yw_bapp/widgets/text_image_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';

class OrderItem extends StatelessWidget {
  final String orderNum;
  final String timeSamp;
  final int centScorePrice;
  final int type;

  const OrderItem(
      {Key key,
      this.orderNum,
      this.timeSamp,
      this.centScorePrice,
      this.type = 1})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return type == 1
        ? Card(
            //z轴的高度，设置card的阴影
            elevation: 5,
            //设置shape，这里设置成了R角
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(5.0)),
            ),
            //对Widget截取的行为，比如这里 Clip.antiAlias 指抗锯齿
            clipBehavior: Clip.antiAlias,
            semanticContainer: false,
            child: getChild(context),
          )
        : nomalItem(context);
  }

// 卡片的风格样式
  Widget getChild(BuildContext context) {
    return Container(
      height: 68,
      color: Colors.white,
      padding: EdgeInsets.all(12),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 订单号
              Text(
                '订单号：$orderNum',
                style: TextStyle(fontSize: 13, color: Colors.black),
              ),
              // 日期
              Text(
                '$timeSamp',
                // '${DateUtils.instance.getFormartData(timeSamp:new DateTime.now().millisecondsSinceEpoch+0 * 24 * 60 * 60 * 1000,format:"yyy/MM/dd  HH:mm:ss")}',
                style: TextStyle(fontSize: 13, color: Colors.black),
              )
            ],
          ),
          TextWithImage(
            title: '+${centScorePrice / 100}',
            imageUrl: 'images/bean.png',
            imgHeight: 12,
            imgWdth: 12,
            textStyle:
                TextStyle(color: ColorUtil.color("#FF333333"), fontSize: 18),
          ),
        ],
      ),
    );
  }

// 普通的一项
  Widget nomalItem(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          border:
              Border(bottom: BorderSide(color: Color.fromRGBO(0, 0, 0, 0.1)))),
      child: getChild(context),
    );
  }
}
